package com.lightsaber.trade.as.service.param;

import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springside.modules.orm.Page;

import com.lightsaber.trade.as.dao.param.ProductTypeDao;
import com.lightsaber.trade.as.entity.param.ProductType;
import com.lightsaber.trade.core.common.util.CurrentUser;
import com.lightsaber.trade.core.dao.BaseDao;
import com.lightsaber.trade.core.service.BaseServiceImpl;

@Service
@Transactional
public class ProductTypeManager extends BaseServiceImpl<ProductType, String> {
    @Autowired
    private ProductTypeDao productTypeDao;

    @Override
    protected BaseDao<ProductType, String> getDao() {
        return productTypeDao;
    }

    public void findPage(ProductType productType, Page<ProductType> page) {
        productTypeDao.findPage(productType, page);
    }

    public List<ProductType> findByCategory(String category) {
        
        return productTypeDao.findByCategory(category);
    }
    
    public String[] findAllCategoryDistinct(){
        return productTypeDao.findAllCategoryDistinct();
    }

    @Override
    public void save(ProductType productType) {

        if (StringUtils.isBlank(productType.getId())) {
            productType.setOrganization(CurrentUser.getOrg());
        }
        
        super.save(productType);
    }
}
